package wlmap;


import javax.swing.*;

import java.awt.*;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;
import java.util.Iterator;




public class SearchLength2

{

    private JFrame jFrame;

    private JComboBox jComboBox1, jComboBox2;

    private JLabel jLabel;

    private JButton jButton;

    private Toolkit toolkit = Toolkit.getDefaultToolkit();
    



    public SearchLength2()

    {



        jFrame = new JFrame();
        jFrame.setLayout(new FlowLayout());

        jFrame.setBounds(700, 200, 400, 200);



        jComboBox1 = new JComboBox();

        jComboBox1.setPreferredSize(new Dimension(180, 30));

        jComboBox1.setFont(new Font("微软雅黑", 1, 20));

        jComboBox2 = new JComboBox();

        jComboBox2.setPreferredSize(new Dimension(180, 30));

        jComboBox2.setFont(new Font("微软雅黑", 1, 20));
        
       
            jComboBox1.addItem("校门");
            jComboBox1.addItem("一号楼");
            jComboBox1.addItem("二号楼");
            jComboBox1.addItem("三号楼");
            jComboBox1.addItem("四号楼");
            jComboBox1.addItem("食堂");
            jComboBox1.addItem("宿舍");
            jComboBox1.addItem("图书馆");

            jComboBox2.addItem("校门");
            jComboBox2.addItem("一号楼");
            jComboBox2.addItem("二号楼");
            jComboBox2.addItem("三号楼");
            jComboBox2.addItem("四号楼");
            jComboBox2.addItem("食堂");
            jComboBox2.addItem("宿舍");
            jComboBox2.addItem("图书馆");

        


        jLabel = new JLabel();

        jLabel.setPreferredSize(new Dimension(350, 80));

        jLabel.setFont(new Font("微软雅黑", 1, 20));

        

        jComboBox1.addItemListener(new ItemListener()

        {

            @Override

            public void itemStateChanged(ItemEvent e)

            {
            	MGraph G = GenerateGraph.generateMGraph();
        		ShortestPath_DIJ2 dij = new ShortestPath_DIJ2();
        		dij.DIJ(G,jComboBox1.getSelectedIndex());
        		String str1="";
        		int m=0;
        		try {
					str1=dij.shortline(G,jComboBox2.getSelectedIndex());
					m=dij.beeline(G,jComboBox2.getSelectedIndex());
				} catch (Exception e1) {
					// TODO 自动生成的 catch 块
					e1.printStackTrace();
				}   
        		
        		

        		jLabel.setText("<html>" + "最优路径:  "  +str1+  "<br>"+"距离：  "+m + "m" + "</html>");

            }

        });

        jComboBox2.addItemListener(new ItemListener()

        {

            @Override

            public void itemStateChanged(ItemEvent e)

            {

            	MGraph G = GenerateGraph.generateMGraph();
        		ShortestPath_DIJ2 dij = new ShortestPath_DIJ2();
        		dij.DIJ(G,jComboBox1.getSelectedIndex());
        		String str1="";
        		int m=0;
        		
        		try {
					str1=dij.shortline(G,jComboBox2.getSelectedIndex());
					m=dij.beeline(G,jComboBox2.getSelectedIndex());
				} catch (Exception e1) {
					// TODO 自动生成的 catch 块
					e1.printStackTrace();
				}   

                jLabel.setText("<html>" + "最优路径:  "  +str1+ "<br>"+ "距离：  "+m + "m" + "</html>");

            }

        });



        jButton = new JButton("确定");

        jButton.addMouseListener(new MouseAdapter()

        {

            @Override

            public void mouseClicked(MouseEvent e)

            {

                jFrame.setVisible(false);

            }

        });



        jFrame.add(jComboBox1);

        jFrame.add(jComboBox2);

        jFrame.add(jLabel);

        jFrame.add(jButton);

        jFrame.setResizable(false);

        jFrame.setVisible(true);
        
    
    	
    	}





}
